import Vue from 'vue'
import ImageModal from '~/components/ImageModal.vue'

const ImageModalPlugin = {
  install(Vue) {
    const ImageModalConstructor = Vue.extend(ImageModal)
    
    let instance = null
    
    Vue.prototype.$showImageModalsss = () => {
        instance.isVisible = false
      }
    Vue.prototype.$showImageModal = (imageSrc,type) => {
      if (instance) {
        instance.imageSrc = imageSrc
        instance.isVisible = true
        instance.type = type
      } else {
        instance = new ImageModalConstructor({
          propsData: {
            imageSrc,
            isVisible: true,
            type: type  
          }
        }).$mount()
        
        document.body.appendChild(instance.$el)
      }
    }
  }
}

Vue.use(ImageModalPlugin)
